package zoom;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;

public class Test1 {
    private static int res = 0;
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());
        String color = " " + br.readLine();
        int[][] matrix = new int[n + 1][n + 1];
        String s;
        while ((s = br.readLine()) != null){
            String[] nodes = s.split(" ");
            matrix[Integer.parseInt(nodes[0])][Integer.parseInt(nodes[1])] = 1;
            matrix[Integer.parseInt(nodes[1])][Integer.parseInt(nodes[0])] = 1;
        }
        dfs(1, new HashSet<>(), matrix, 0, 0, color);
        System.out.println(res);
    }
    public static void dfs(int index, Set<Integer> visited, int[][] matrix, int red, int blue, String color){
        visited.add(index);
        if (color.charAt(index) == 'R') red++;
        else blue++;
        res += Math.abs(red - blue);
        for (int i = 1; i <= matrix.length - 1; i++){
            if (matrix[index][i] == 1 && !visited.contains(i)) {
                dfs(i, visited, matrix, red, blue, color);
            }
        }
    }
}
